package swd.maintain.project.prg_in_sys_maintain;

import com.pub.database.*;

public class Flow {
   QueryBean gqbnDAO=null;
   String gstrLoginUser=null;
   String gstrFlowCode=null;
   View gView=null;
   Business gBusiness=null;
   public Flow(QueryBean pqbnDAO,String pstrLoginUser,String pstrFlowCode,View pview,Business pBusiness){
      gqbnDAO=pqbnDAO;
      gstrLoginUser=pstrLoginUser;
      gstrFlowCode=pstrFlowCode;
      gView=pview;
      gBusiness=pBusiness;
   }
   public void preAddAction(String pstrUserID){
      try{
         //gView.setflow_code(gstrFlowCode);
         //gView.setflow_num(new GetFlowNum(gqbnDAO.getDBType(),gqbnDAO.getConnection()).getFlowNum(gstrFlowCode));
         gBusiness.setInitValueForAdd(gView,pstrUserID);
         gBusiness.setReadonlyForAdd(gView);
      }
      catch(Exception e){
         e.printStackTrace();
      }
   }
   public String addAction(){
      String lstrNotNullList = null;
      String lstrAddStep = null;
      String lstrInsResult=null;
      try {
         lstrAddStep="檢查必填欄位";
         lstrNotNullList = gBusiness.checkNotNullFld(gView);

         if (lstrNotNullList.equals("")) {
            lstrAddStep="新增存檔";
            lstrInsResult=gBusiness.exeInsSQL(gView);
            if(lstrInsResult.equals("")){
               lstrAddStep="送出流程";
               //(new FlowExpand("O",gqbnDAO.getConnection())).expandFlow(gView.getflow_code(),gView.getflow_num(),"null",gView.getempno());
            }else{
                return "新增資料至" + lstrInsResult + "發生錯誤!!";
            }
         } else {
            return lstrNotNullList;
         }
         gView.setPrgStatus("null");
         return "資料新增成功!!";
      } catch (Exception e) {
         e.printStackTrace();
         return "程式執行至" + lstrAddStep + "時發生錯誤!!";
      }
   }
}
